import PageTemplates from "PageTemplates";
import { Common } from 'UtilsCommon';
const { EntityPageEdit } = PageTemplates;

export default EntityPageEdit("rightGroupEdit", "RightGroup", '权限组-编辑', 500, {
    expandInit() {
        this.menuList = this.getProperty('MenuList');
    },
    expandSetEntityData({ entityData }) {
        entityData.RightGroupId = this.pageData.RightGroupId || Common.createGuid();

        const list = [];

        if (entityData.MenuList) {
            entityData.MenuList.forEach(d => {
                list.push({
                    Id: Common.createGuid(),
                    RightGroupId: entityData.RightGroupId,
                    MenuKey: d
                });
            });
        }

        entityData.Menus = list;
        delete entityData.MenuList;

        return entityData;
    },
    setGetEntityDataLoad({ data }) {
        if (data.Menus && data.Menus.length > 0) this.menuList.setValue(data.Menus.map(m => m.MenuKey));
    }
});